/**
 * 功能描述
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	
    module.exports = {
    		formBlurEvents : function(widget){
    			var signUpForm = widget.get("signupform");
    			var destination = signUpForm.getValue("destination");
    			var startDate = signUpForm.getValue("startDate");
    			var endDate = signUpForm.getValue("endDate");
    			
    			if(destination == "" || startDate == "" || endDate == ""){
    				return false;
    			}
    			
    			aw.ajax({
    				url: "api/checkinimplement/query",
    				data: {
    					"statusIn": "Confirmed,Edited,Doing,Confirmed,Initial",
    					"groupReserve.planItemGroup.planItem.startDate" : moment(startDate).format("x"),
    					"groupReserve.planItemGroup.planItem.endDate" : moment(endDate).format("x"),
    					"groupReserve.planItemGroup.planItem.destination" : destination,
    					"groupReserve.checkInType":"Organization",
    					fetchProperties: "signUpNum,groupReserve.planItemGroup.allianceOrg.name," +
    							"groupReserve.planItemGroup.servicePoint.name," +
    							"groupReserve.planItemGroup.servicePoint.pkServicePoint," +
    							"roomPersonalInfos.pkRoomPersonalInfo," +
								"roomPersonalInfos.version," +
								"roomPersonalInfos.checkIn," +
								"roomPersonalInfos.roomRegister.pkRoomRegister," +
								"roomPersonalInfos.roomRegister.version," +
								"roomPersonalInfos.roomRegister.room.pkRoom," +
								"roomPersonalInfos.roomRegister.room.code," +
								"roomPersonalInfos.roomRegister.room.roomType.name," +
								"roomPersonalInfos.signUpRegister.member," +
								"roomPersonalInfos.signUpRegister.pkSignUpRegister," +
								"roomPersonalInfos.signUpRegister.exitGroup," +
								"roomPersonalInfos.signUpRegister.personalInfo.idNumber," +
								"roomPersonalInfos.signUpRegister.personalInfo.name," +
								"roomPersonalInfos.signUpRegister.personalInfo.sex.*," +
								"roomPersonalInfos.signUpRegister.personalInfo.mobilePhone," +
								"roomPersonalInfos.signUpRegister.travelContract.member.personalInfo.idNumber," +
								"roomPersonalInfos.signUpRegister.travelContract.member.personalInfo.name," +
								"roomPersonalInfos.signUpRegister.travelContract.productRule.product.name," +
								"roomPersonalInfos.signUpRegister.travelContract.memberCertificates,"
    				},
    				dataType: "json",
    				success: function(datas){
    					if(datas.length == 0){
    						return false;
    					}
    					var data = datas[0];
    					signUpForm.setData({
    						groupUnit : data.groupReserve.planItemGroup.alliance ? 
    								data.groupReserve.planItemGroup.allianceOrg.name : 
    									data.groupReserve.planItemGroup.servicePoint.name,
    						count: data.signUpNum,
    						servicePoint: data.groupReserve.planItemGroup.servicePoint.pkServicePoint
    					});
    					
    					var signupgrid = widget.get("signupgrid");
    					signupgrid.setData(data.roomPersonalInfos);
    				}
    			})
    			
    		}
    };
});
